<template>
	<view>
		<!-- 切换 -->
		<u-sticky>
			<view class="lb-tabs">
				<view class="tabs-item" :class="tabsIndex == index?'active':''" v-for="(item,index) in tabsData"
					:key="index" @click="clickTabs(index)">
					<view class="text">
						<view class="name">
							{{item.name}}
						</view>
						<view class="numb" :class="index == 0?'numb-p':'numb-m'">
							{{item.numb}}
						</view>
					</view>
					<view class="btn">

					</view>
				</view>
			</view>
			<!-- 搜索 -->
			<view class="lb-search" v-if="tabsIndex == 0">
				<u-search height="80rpx" bgColor="#fff" placeholderColor="#333" color="#333" placeholder="搜索"
					borderColor="#E7E7E7" v-model="keyword" :showAction="false" @search="search"></u-search>
			</view>
		</u-sticky>
		<view class="lb-main-32" :class="tabsIndex == 0?'lb-main-p0':''">
			<!-- 团队 -->
			<view class="lb-list" v-if="tabsIndex == 0" v-for="(item,index) in listData" :key="index">
				<view class="lb-item">
					<view class="item-top">
						<view class="lb-left">
							<u-avatar :src="getImgUrl(item.avatar)" size="80rpx"></u-avatar>
						</view>
						<view class="lb-right">
							<view class="lb-name">
								{{item.name}} <text>{{item.mobile}}</text>
							</view>
							<view class="lb-time">
								{{item.createtime}}
							</view>
						</view>
					</view>
					<view class="item-foot">
						<view class="foot-box">
							提现：￥{{item.cash}}
						</view>
						<view class="foot-box">
							订单：{{item.order_num}}
						</view>
						<view class="foot-box">
							用户：{{item.num}}
						</view>
					</view>
				</view>
			</view>
			<!-- 业绩 -->

			<view class="lb-box" v-if="tabsIndex == 1">
				<view class="lb-item">
					<view class="price">
						{{data.today || 0}}
					</view>
					<view class="label">
						今日业绩
					</view>
				</view>
				<view class="lb-item">
					<view class="price">
						{{data.month || 0}}
					</view>
					<view class="label">
						本月业绩
					</view>
				</view>
				<view class="lb-item">
					<view class="price">
						{{data.total_num || 0}}
					</view>
					<view class="label">
						累计业绩
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		distributionApiTeam,
		distributionApiTeamGrade,
		// distributionApiTeamNumb,
		teamCountApi
	} from "@/api/apis/retail.js"
	import {
		setImgUrl
	} from "@/utils/comm.js"
	export default {
		data() {
			return {
				tabsIndex: 0,
				tabsData: [{
						name: '团队总人数',
						numb: 0
					},
					{
						name: '团队业绩',
						numb: 0
					},
				],
				keyword: '',
				page: 1,
				limit: 10,
				listData: [],
				isLoading: false,
				data: ''
			}
		},
		onLoad() {
			this.getData();
			this.getList();
		},
		methods: {
			//切换
			clickTabs(i) {
				this.tabsIndex = i;
				if (i == 0) {
					this.page = 1;
					this.getList();
				} else {
					this.getGrade();
				}
			},
			//跳转
			goTo(url) {
				if (url) {
					uni.navigateTo({
						url: url
					})
				}
			},
			//搜索
			search() {
				this.page = 1;
				this.getList();
			},
			getImgUrl(url) {
				return setImgUrl(url);
			},
			//数据
			getData() {
				uni.showLoading({
					title: "加载中",
					mask: true
				});
				teamCountApi().then(res => {
					uni.hideLoading();
					this.tabsData[0].numb = res.data.num;
					this.tabsData[1].numb = res.data.grade;
				})
			},
			//业绩
			getGrade() {
				uni.showLoading({
					title: "加载中",
					mask: true
				});
				distributionApiTeamGrade().then(res => {
					uni.hideLoading();
					this.data = res.data;
				})
			},
			//列表
			getList() {
				uni.showLoading({
					title: "加载中",
					mask: true
				});
				this.isLoading = true;
				distributionApiTeam({
					// is_recommend: 1,
					type: this.tabsIndex + 1,
					page: this.page,
					limit: this.limit,
					keywords: this.keyword
				}).then(res => {
					uni.hideLoading();
					let data = res.data;
					if (this.page == 1) {
						this.listData = data.data;
					} else {
						this.listData = this.listData.concat(data.data);
					}
					if (data.total > this.page * this.limit) {
						// console.log(res.data.length)
						//请求成功 节流阀 设置为false（没有走完函数不允许再次请求）
						this.isLoading = false;
						this.page++;
					}
				})
			},
		},
		onReachBottom() {
			//注意 这里是重要的一步，不满足条件下拉加载不能继续请求数据
			if (!this.isLoading && this.tabsIndex == 0) {
				this.getList();
			}

		},
	}
</script>

<style lang="scss">
	.lb-main-p0 {
		padding-top: 0rpx;
	}

	.lb-tabs {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		background-color: #FFFFFF;

		.tabs-item {
			width: calc(100% - 2rpx);
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;
			box-sizing: border-box;
			border-bottom: 1rpx solid #F5F5F5;



			.text {
				font-size: $main-font-28;
				color: $main-font-color;
				font-weight: bold;
				padding: 24rpx 0 12rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.name {}

				.numb {}

				.numb-p {
					&::after {
						content: '人';
					}
				}

				.numb-m {
					&::after {
						content: '元';
					}
				}


			}

			.btn {
				height: 0;
				width: 0;
				border-width: 10rpx;
				border-style: solid;
				border-color: transparent transparent transparent transparent; //分别为上右下左
			}
		}

		.active {
			border-bottom: 2rpx solid #00D26E;

			.text {
				color: #00D26E;

			}

			.btn {
				border-color: transparent transparent #00D26E transparent; //分别为上右下左
			}
		}

	}

	//搜索
	.lb-search {
		padding: 32rpx;
		background: linear-gradient(180deg, #FFFFFF 0%, #F5F5F5 100%);
	}

	//列表
	.lb-list {
		display: flex;
		background: rgba(255, 255, 255, 1);
		padding: 24rpx 0;
		border-radius: 16rpx;
		box-sizing: border-box;
		margin-bottom: 30rpx;


		.lb-item {
			width: 100%;
			display: flex;
			flex-direction: column;


			.item-top {
				display: flex;
				padding: 0 32rpx 24rpx;

				.lb-left {}

				.lb-right {
					display: flex;
					flex-direction: column;
					width: calc(100% - 80rpx);
					justify-content: space-between;
					padding-left: 24rpx;

					.lb-name {
						font-size: $main-font-28;
						color: $main-font-color;


						text {
							font-size: $main-font-24;
							color: $main-font-color-grey6;
							padding-left: 24rpx;
						}
					}

					.lb-time {
						font-size: $main-font-28;
						color: $main-font-color-grey9;
					}
				}

			}

			.item-foot {
				display: grid;
				grid-template-columns: repeat(3, 1fr);
				grid-gap: 30rpx;
				padding: 24rpx 32rpx 0;
				border-top: 2rpx solid #F5F5F5;


				.foot-box {
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: $main-font-28;
					color: $main-font-color;
				}
			}
		}

	}

	.lb-box {
		display: grid;
		grid-template-columns: repeat(3, 1fr);
		grid-gap: 30rpx;

		// padding: 20rpx 0;
		.lb-item {
			background: linear-gradient(to bottom right, #B6E8FD, #4F99F5);
			height: 218rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			border-radius: 16rpx;

			&:nth-of-type(3n-1) {
				background: linear-gradient(to bottom right, #FEE4B6, #FE835D);

			}

			&:nth-of-type(4n-1) {
				background: linear-gradient(to bottom right, #FEDDD6, #FD6344);

			}

			.price {
				font-size: $main-font-32;
				color: $main-font-color-white;

				&::before {
					content: '¥ ';
					font-size: $main-font-20;
				}
			}

			.label {
				font-size: $main-font-28;
				color: $main-font-color-white;
				padding-top: 18rpx;
			}
		}

	}
</style>